package br.it.teste.banco;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class BancoHelper {
	private static String driver	= "com.mysql.jdbc.Driver";
	private static String url 		= "jdbc:mysql://localhost/NovaDelegacia";
	private static String usuario 	= "root";
	private static String senha 	= "root123";
	
	private static Connection conexao;
	
	public static Connection getConexao(){
		
		try {
			
			if(conexao == null || conexao.isClosed()) {
				//abrindo conexao!
				Class.forName(driver);
				conexao = DriverManager.getConnection(url, usuario, senha);
			} 
			
		} catch (ClassNotFoundException e) {
			System.out.println("Deu erro na hora de carregar o driver!");
			e.printStackTrace();
		} catch (SQLException e) {
			System.out.println("Deu erro na hora de estabelecer conexao!");
			e.printStackTrace();
		} 
			
		return conexao;
		
	}
	
}
